package com.multitrack.map;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;

import com.google.android.maps.GeoPoint;

public class Polyline {
	ArrayList<GeoPoint> line;
	
	public Polyline(ArrayList<GeoPoint> line) {
		this.line = line;
	}
	
	public Polyline() {
		this.line = new ArrayList<GeoPoint>();
	}
	
	public boolean add(GeoPoint vertex) {
		if(line == null) {
			return false;
		}
		
		line.add(vertex);		
		return true;
	}
	
	public int size() {
		if(line == null) {
			return -1;
		}
		return line.size();
	}

	public Iterator<GeoPoint> iterator() {
		PolylineIterator p = new PolylineIterator(line);
		return null;
	}
	
	public class PolylineIterator implements Iterator<GeoPoint> {
		private int index;
		private ArrayList<GeoPoint> line;

		public PolylineIterator(ArrayList<GeoPoint> coordinates) {
			index = 0;
			this.line = coordinates;
		}

		public boolean hasNext() {
			return index < line.size();
		}

		public GeoPoint next() {
			if (hasNext()) {
				return line.get(index++);
			} else {
				throw new NoSuchElementException();
			}
		}

		public void remove() {
			throw new UnsupportedOperationException();
		}
	}
}
